package org.vectrics.recruiter.struts.admin;

import java.util.Collection;
import java.util.HashSet;

import org.vectrics.hibernate.ThreadProperties;
import org.vectrics.provider.CoreServiceLocator;
import org.vectrics.recruiter.RecruitServiceLocator;
import org.vectrics.recruiter.job.JobCandidateCriteria;
import org.vectrics.recruiter.job.JobSearchCriteria;
import org.vectrics.user.Person;

public class AdminJobPostingsSummaryTag extends AdminSummaryBaseTag {
	/**
	 * 
	 */
	private static final long serialVersionUID = 57016069033638821L;

	public AdminJobPostingsSummaryTag() {
		super();
	}
	
	protected String getHeader() {
		return CoreServiceLocator.getPhraseProvider().getMessage("heading.job.summary", this.getLocale());
	}
	
	protected void fillContentCell() {
		JobSearchCriteria criteria = new JobSearchCriteria();
		criteria.setJobsNeedingApproval(true);
		criteria.addDomain(ThreadProperties.getDomain());
		criteria.getDomains().addAll(ThreadProperties.getDomain().retrieveChildrenInBranch());
		int approvalCount = RecruitServiceLocator.getJobProvider().findJobCount(criteria);
		
		this.addContentRow("" + approvalCount + " jobs are in a state that may require approval.",
				 this.getContextPath() + "/admin/jobs/showlist.do?needApproval=true", "view");
		
		showNewApplicantSummary();
	}
	
	private void showNewApplicantSummary() {
		
	    JobCandidateCriteria criteria = new JobCandidateCriteria();
	    Collection statuses = new HashSet();
	    statuses.add("cand-appl");
	    criteria.setStatusSet(statuses);
        Person observer = this.getAuthPerson();
        criteria.setObserver(observer);

		int applicantCount = RecruitServiceLocator.getJobProvider().findJobCandidatesCount(criteria); 
		this.addContentRow("" + applicantCount + " new applicants for jobs.",
				 this.getContextPath() + "/admin/user/applicants.do", "view");
		
	}

}
